<template>
  <div class="homelists" @click="gettitl">
    <loading v-if="isLoading"></loading>
    <div class="hed">
      <hr />
      <h3 class="f-cb">
        <span class="gradient">重磅推荐</span>
        <router-link to class="more">更多</router-link>
      </h3>
      <div class="bookbox">
        <ul>
          <li v-for="item in book_list[0]">
            <router-link :to="`/cs?id=${item.id}&title=${item.title}`">
              <div class="book-1">
                <img :src="item.cover" alt="" />
              </div>
              <div class="text-1">
                <h4>{{ item.title }}</h4>
                <p>{{ item.author }}</p>
              </div>
            </router-link>
          </li>
        </ul>
      </div>
      <div class="booklist">
        <ul>
          <li v-for="item in book_list[1]">
            <router-link :to="`/cs?id=${item.id}&title=${item.title}`">
              <div class="book-1">
                <img :src="item.cover" alt="" />
              </div>
              <div class="text-1">
                <h4>{{ item.title }}</h4>
                <p class="name-1">{{ item.author }}</p>
                <p class="p-1">
                  {{ item.content }}
                </p>
                <p class="tag-1">
                  <span>连载</span>
                  <span>{{ item.category }}</span>
                  <span
                    >点击：{{ (item.clickCount / 10000).toFixed(2) }}万</span
                  >
                </p>
              </div>
            </router-link>
          </li>
        </ul>
      </div>
    </div>
    <div class="hed">
      <hr />
      <h3 class="f-cb">
        <span class="gradient">都市爽文</span>
        <router-link to class="more">更多</router-link>
      </h3>
      <div class="booklist">
        <ul>
          <li v-for="item in book_list[2]">
            <router-link :to="`/cs?id=${item.id}&title=${item.title}`">
              <div class="book-2">
                <img :src="item.cover" alt="" />
              </div>
              <div class="text-2">
                <h4>{{ item.title }}</h4>
                <p class="name-2">{{ item.author }}</p>
                <p class="p-2">
                  {{ item.content }}
                </p>
                <p class="tag-2">
                  <span>连载</span>
                  <span>{{ item.category }}</span>
                  <span
                    >点击：{{ (item.clickCount / 10000).toFixed(2) }}万</span
                  >
                </p>
              </div>
            </router-link>
          </li>
        </ul>
      </div>
    </div>
    <div class="hed">
      <hr />
      <h3 class="f-cb">
        <span class="gradient">大家都在看</span>
        <router-link to class="more">更多</router-link>
      </h3>
      <div class="booklist">
        <ul>
          <li v-for="item in book_list[3]">
            <router-link :to="`/cs?id=${item.id}&title=${item.title}`">
              <div class="book-3">
                <img :src="item.cover" alt="" />
              </div>
              <div class="text-3">
                <h4>{{ item.title }}</h4>
                <p class="name-3">{{ item.author }}</p>
                <p class="p-3">
                  {{ item.content }}
                </p>
                <p class="tag-3">
                  <span>连载</span>
                  <span>{{ item.category }}</span>
                  <span
                    >点击：{{ (item.clickCount / 10000).toFixed(2) }}万</span
                  >
                </p>
              </div>
            </router-link>
          </li>
        </ul>
      </div>
    </div>
    <div class="hed">
      <hr />
      <h3 class="f-cb">
        <span class="gradient">完本精选</span>
        <router-link to class="more">更多</router-link>
      </h3>
      <div class="booklist">
        <ul>
          <li v-for="item in book_list[4]">
            <router-link :to="`/cs?id=${item.id}&title=${item.title}`">
              <div class="book-4">
                <img :src="item.cover" alt="" />
              </div>
              <div class="text-4">
                <h4>{{ item.title }}</h4>
                <p class="name-4">{{ item.author }}</p>
                <p class="p-4">
                  {{ item.content }}
                </p>
                <p class="tag-4">
                  <span class="vip">完结</span>
                  <span>{{ item.category }}</span>
                  <span
                    >点击：{{ (item.clickCount / 10000).toFixed(2) }}万</span
                  >
                </p>
              </div>
            </router-link>
          </li>
        </ul>
      </div>
    </div>
    <div class="hed butom">
      <hr />
      <h3 class="f-cb">
        <span class="gradient">畅销榜</span>
        <router-link to class="more">更多</router-link>
      </h3>
      <div class="bookbox">
        <ul>
          <li v-for="(item, i) in book_list[5]">
            <router-link :to="`/cs?id=${item.id}&title=${item.title}`">
              <b :class="'rank-' + (i + 1)"></b>
              <div class="book-1">
                <img :src="item.cover" alt="" />
              </div>
              <div class="text-tb">
                <h4>{{ item.title }}</h4>
                <p>{{ item.author }}</p>
              </div>
            </router-link>
          </li>
        </ul>
      </div>
    </div>
    <mix-search></mix-search>
  </div>
</template>
<script>
import Loading from "@/components/loading/indexlist.vue";
import MixSearch from "../search/mixsearch.vue";
import { recommendFunc, reFunc } from "@/request/index";
export default {
  components: {
    MixSearch,
    Loading
  },
  data() {
    return {
      book_list: [],
      list_title: [],
      url: "",
      title: "",
      isLoading: true,
    };
  },
  methods: {
    async csfe() {
      this.isLoading=true
      await recommendFunc()
        .then((res) => {
          // console.log(res.data);
          let { navi } = res.data;
          // console.log(navi);
          this.url = navi[2].url;
          // console.log(this.url)
          reFunc(navi[2].url)
            .then((lis) => {
              // console.log(lis);
              let { list } = lis.data;
              this.book_list = list.map((item) => {
                // console.log(item);
                let { list } = item;
                // console.log(list);
                return item.list;
              });
              this.book_list.splice(0, 1);
              // console.log(this.book_list[3]);
            })
            .catch((err) => {
              console.log("请求失败...");
            });
            this.isLoading = false;
        })
        .catch((err) => {
          console.log("请求失败...");
        });
    },
    gettitl(e) {
      // console.log(e.target.className);
      if (e.target.textContent === "更多") {
        // console.log(e.target.parentNode.firstChild.textContent);
        this.title = e.target.parentNode.firstChild.textContent;
        let titles = this.title;
        let urls = this.url;
        this.$router.push(`/modo?list_title=${titles}&url=${urls}`);
      }
      // console.log(this.title);
    },
  },
  created() {
    this.csfe();
    // this.getlist()
  },
};
</script>
<style lang="scss">
@import url(../../static/css/reset.css);
.butom {
  .p-3{
    width: 200px;
  }
  box-sizing: border-box;
  li {
    box-sizing: border-box;
    position: relative;
    b {
      position: absolute;
      top: -2px;
      left: 7.8px;
      right: 0;
      width: 86%;
      height: 22px;
      background: 0 0 no-repeat;
      background-size: 100% auto;
      z-index: 9;
      &.rank-1 {
        background-image: url(../../static/imgs/icon_01.png);
      }
      &.rank-2 {
        background-image: url(../../static/imgs/icon_02.png);
      }
      &.rank-3 {
        background-image: url(../../static/imgs/icon_03.png);
      }
    }
    h4 {
      font-size: 15px;
      line-height: 19px;
      height: 38px;
      max-height: 38px;
      margin: 10px 0 5px;
      overflow: hidden;
      color: #222;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
    p {
      color: #888;
      line-height: 15px;
      height: 15px;
      font-size: 12px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
}
.homelists {
  margin: auto 5%;
  margin-top: 3px;
  .hed {
    width: 100%;
    h3 {
      height: 28px;
      line-height: 28px;
      margin-bottom: 16px;
      font-weight: bold;
      .gradient {
        float: left;
        display: inline-block;
        font-size: 20px;
        color: #1a1a1a;
      }
      .more {
        float: right;
        padding: 0 17px;
        font-size: 13px;
        font-weight: normal;
        color: #999;
        box-sizing: border-box;
        border: 1px solid #f0f0f0;
        border-radius: 28px;
      }
    }
    .bookbox {
      width: 100%;
      // background: black;
      ul {
        display: flex;
        li {
          width: 34%;
          [class^="book"] {
            margin: 9px;
            img {
              width: 94px;
              height: 132px;
              border-radius: 5px;
            }
          }
          [class^="text"] {
            color: #333;
            outline: none;
            padding-left: 10%;
            text-align: start;
            h4 {
              font-size: 15px;
              line-height: 19px;
              height: 38px;
              max-height: 38px;
            }
            p {
              color: #888;
              line-height: 15px;
              height: 15px;
              font-size: 12px;
            }
          }
        }
      }
    }
    .booklist {
      margin-top: 20px;
      width: 100%;
      // background: black;
      ul {
        li {
          display: flex;
          width:327px;
          [class^="book"] {
            width: 30%;
            margin: 9px;
            float: left;
            img {
              width:98.1px;
              height: 132px;
              border-radius: 5px;
            }
          }
          [class^="text"] {
            width: 342px;
            padding-top: 10px;
            color: #333;
            outline: none;
            padding-left: 10px;
            text-align: start;
            h4 {
              font-size: 15px;
              line-height: 19px;
              height: 38px;
              max-height: 38px;
            }
            [class^="name"] {
              color: #888;
              line-height: 15px;
              height: 15px;
              font-size: 12px;
              margin-bottom: 5px;
              -webkit-line-clamp: 2;
              overflow: hidden;
            }
            [class^="p"] {
              box-sizing: border-box;
              color: #888;
              line-height: 18px;
              // width: 226.7px;
              height: 36px;
              -webkit-line-clamp: 2;
              display: -webkit-box;
              -webkit-box-orient: vertical;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: wrap;
            }
            [class^="tag"] {
              padding-top: 13px;
              span {
                display: inline-block;
                margin-right: 2px;
                padding: 0 12px;
                height: 22px;
                line-height: 22px;
                font-size: 12px;
                color: #999;
                background-image: linear-gradient(
                  3deg,
                  #f9f9f9 0,
                  #f0f0f0 100%
                );
                border-radius: 22px;
                &.vip {
                  color: red;
                  background-image: linear-gradient(3deg, gold 0, gold 100%);
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>
  